
chrome.storage.sync.get(['csdn'], function(result) {
    console.log('CSDN.js: Value currently is ' + result.csdn);
    if (result.csdn) csdnSimple();
});

function csdnSimple() {

if (!document.URL.includes("csdn.net")) {
    return;
}

insertCss('csdn.css')
insertJs('xcopy.js')

let {ful_scr_toolbar,ful_scr_toolbar_close} = inject_iReaderBar()
let codes = document.getElementsByClassName("hljs-button")

if (codes) {
    for (let code of codes) {
        code.setAttribute('onclick', "onCopyCode(event)")
        code.parentNode.onmouseenter=()=>{
            code.setAttribute('data-title', "复制（爱读V2）")
        }
    }
}

////////////////////////////
let asideSearchArticle = document.getElementById("asideSearchArticle");

if (asideSearchArticle && asideSearchArticle.nextSibling) {
    asideSearchArticle.nextSibling.display="none"
}

//csdn-shop-window-top
let csdn_shop_window_top = document.getElementById("csdn-shop-window-top");
if (csdn_shop_window_top) {
    csdn_shop_window_top.style.display="none"
}

let csdn_right_aside = document.getElementById("rightAside");
let blog_container_aside = document.getElementsByClassName("blog_container_aside");

let main = document.getElementsByTagName("main")[0];
document.body.appendChild(ful_scr_toolbar);

let contentBox = document.getElementsByClassName("blog-content-box")[0];
let csdnToolbar = document.getElementById("csdn-toolbar");

let bodyLastBgColor = main?main.style.background:"";

function exitFullScreen() {
    document.body.className = document.body.className.replace("iread_body", "");
    ful_scr_toolbar.className = "ful_scr_toolbar_notful";
    ful_scr_toolbar_close.textContent = "+";

    if (main) {
        main.className = "";
        main.style.background = bodyLastBgColor;
    }

    if (csdn_right_aside) {
        csdn_right_aside.style.display=""
    }
    
    if (blog_container_aside[0]) {
        blog_container_aside[0].className = blog_container_aside[0].className.replace("iread-aside", "");
        blog_container_aside[0].left = "auto";
    }

    if (csdnToolbar) csdnToolbar.className = csdnToolbar.className.replace("iread_hide_toolbar", "");
    if (contentBox) contentBox.className = contentBox.className.replace("iread_blog_content_box", "");
    
    document.body.scrollIntoView();
    showDonate(false);
}

function enterFullScreen() {
    document.body.className += " iread_body";
    ful_scr_toolbar.className = "ful_scr_toolbar"
    ful_scr_toolbar_close.textContent = "×";

    chrome.storage.sync.get(['bgcolor'], function(result) {
        if(main) main.setAttribute('style', "background:"+result.bgcolor+" !important");
        //document.body.style.background = result.bgcolor + " !important";
    });

    if (csdn_right_aside) {
        csdn_right_aside.style.display="none"
    }

    if (blog_container_aside[0])blog_container_aside[0].className += " iread-aside";
    if(main) main.className = "iread_main";
    if (csdnToolbar) csdnToolbar.className += " iread_hide_toolbar";
    if (contentBox) contentBox.className += " iread_blog_content_box";

    document.body.scrollIntoView();
    showDonate(true);
}

ful_scr_toolbar_close.onclick=()=> {
    if (main && main.className) {
        exitFullScreen();
    } else {
        enterFullScreen();
    }
};

chrome.storage.sync.get(['i_csdn'], function(result) {
    console.log('csdn.js: auto is ' + result.i_csdn);
    if (result.i_csdn) enterFullScreen();
});
}
